package com.pharmcube.xjy.controller.sqlToDsl;

import com.pharmcube.xjy.es4sql.MainTestSuite;
import com.pharmcube.xjy.es4sql.SearchDao;
import com.pharmcube.xjy.es4sql.exception.SqlParseException;
import com.pharmcube.xjy.es4sql.query.QueryAction;
import com.pharmcube.xjy.es4sql.query.SqlElasticRequestBuilder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLFeatureNotSupportedException;

@Api(tags = "sql转dsl")
@RestController
@RequestMapping("/sqlToDsl")
public class SqlToDslController {
    @RequestMapping(value = "/convertToDsl", method = {RequestMethod.POST})
    @ResponseBody
    @ApiOperation(value = "sql转换为dsl", notes = "sql转换为dsl", httpMethod = "POST")
    public String convertToDsl(@RequestParam String sql) throws SqlParseException, SQLFeatureNotSupportedException {
        SearchDao searchDao = MainTestSuite.getSearchDao();
        QueryAction queryAction = searchDao.explain(sql);
        SqlElasticRequestBuilder requestBuilder = queryAction.explain();
        return requestBuilder.explain();
    }
}
